<?php


namespace Biz\model\brandRights;


trait brandRightsBasicTrait
{

    public static function getInfo($where, $select = '*')
    {
        return static::get($select, $where);
    }

    public static function selectList($where, $select = '*')
    {
        return static::select($select, $where);
    }

    public static function selectCount($where)
    {
        return static::count($where);
    }

    public static function insertData($data)
    {
        $addtimeField = static::$addtimeField ?? 'addtime';
        $edittimeField = static::$edittimeField ?? 'edittime';
        if (!isset($data[$addtimeField])) {
            $data[$addtimeField] = date('Y-m-d H:i:s');
        }
        if (!isset($data[$edittimeField])) {
            $data[$edittimeField] = date('Y-m-d H:i:s');
        }
        $ret = static::insert($data);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return self::id();
    }

    public static function updateData($data, $where)
    {
        $edittimeField = static::$edittimeField ?? 'edittime';
        if (!isset($data[$edittimeField])) {
            $data[$edittimeField] = date('Y-m-d H:i:s');
        }
        $ret = static::update($data, $where);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return true;
    }

    public static function deleteData($where)
    {
        $deleteField = static::$deleteField ?? 'data_status';
        $data[$deleteField] = static::STATUS_DELETE;
        return static::updateData($data, $where);
    }

}